define(['jquery','cookie'], () => {
class Header {
    constructor () {
        this.loadHTML().then(() => {
            this.calcCartCount()
            this.headPwd()
        })
    }
    loadHTML () {
        return new Promise((resolve, reject)=>{
            $('header').load('/html/modules/header.html',() => {
                resolve()
            })
        })
    }
    headPwd(){
        const cookie = $.cookie(name)
        if(Object.keys(cookie).length != 0){
            $('#userName').html(cookie.name)
            $('#dlBefore').hide()
            $('#dlAfter').show()
        }else{
            $('#dlBefore').show()
            $('#dlAfter').hide()
        }
        $('#tuichu').on('click', function(){
            $.cookie("name", "name", {expires: -1, path: '/'});
            $('#dlBefore').show()
            $('#dlAfter').hide()
        })
    }
    calcCartCount () {
        let count = 0
        let cart = localStorage.getItem('cart')
        if (cart) {
            cart = JSON.parse(cart)
            count = cart.reduce((num, shop) => {
                num += shop.count
                return num
            },0)
        }
        $('#Top_shopNum').html(count)
        $('#shopNum').html(count)
    }
}
return new Header()
})